/*
 * Main Routine MC9S08SH8
 * main.c
 *
 * Created on: 14/04/2011
 * Author: Leandro Perez Guatibonza
 */

/*
 * Include Section
 */
#include "core.h"       // Core Routines MC9S08SH8
#include "lcd.h"       // Core Routines MC9S08SH8

/*
 * Function Main
 */
void main(void)
{
    byte newCharacter[5] = {1,2,3,4,5};
    byte variable = 200;
    byte mensaje[] = "Message LCD";

    // Pin configured as output
    pinConfigureOutput(PTAD, 0);

    // Pin configured as input
    pinConfigureInput(PTAD, 1);

    // Read the status of a pin
    //byte readPin = pinRead(PTAD, 1);

    // Send a state to a pin
    pinWrite(PTAD, 0, 0);
    pinWrite(PTAD, 0, 1);

    // Set a Pull-Up on a pin
    pinConfigurePullUp(PTAD, 1);

    // Configure Slew Rate on a pin
    pinConfigureSlewRate(PTAD, 0);

    // Configure a Drive Strength on a pin
    pinConfigureDriveStrength(PTAD, 0);

    // Enable the interrupt on a pin
    pinEnablePinInterrupt(PTAD, 1, 0);

    // Enable the interrupt on a pin
    pinDisablePinInterrupt(PTAD, 1);

    // Enable pin interrupts
    pinEnableInterrupts(0);

    // Disable pin interrupts
    pinDisableInterrupts();

    // Generates a delay in milliseconds
    delayMilliseconds(200);

    // Generates a delay in milliseconds
    delaySeconds(2);

    // Initialize LCD
    lcdInit();

    // Send command or data to LCD
    lcdSend(LCD_INSTRU, 0xAA);
    lcdSend(LCD_DATA, '5');

    // Clean LCD screen
    lcdClear();

    // Sets the LCD cursor Home position
    lcdHome();

    // Set the cursor position of LCD
    lcdSetCursor(1, 1);

    // Set the cursor blink in the LCD
    lcdBlinkCursor(TRUE);
    lcdBlinkCursor(FALSE);

    // Set whether the cursor on the LCD is visible
    lcdVisibleCursor(TRUE);
    lcdVisibleCursor(FALSE);

    // Set if the LCD is turned on or turn off
    lcdStateDisplay(TRUE);
    lcdStateDisplay(FALSE);
 
    // Set the scroll direction of the LCD
    lcdDirectionScroll(LCD_SCROLL_LEFT);
    lcdDirectionScroll(LCD_SCROLL_RIGHT);

    // Set the autoscroll of the LCD
    lcdAutoScroll(TRUE);
    lcdAutoScroll(FALSE);

    // Create a character on the LCD DDRAM
    lcdCreateCharacter(0xC0, newCharacter);

    // Prints a variable in the LCD, in the format provided
    lcdPrint(variable, 0);
    lcdPrint(variable, 1);
    lcdPrint(variable, 2);
    lcdPrint(variable, 3);
    
    // Send a message to the LCD
    lcdSendMessage(1, 1, mensaje);

    for(;;)
    {
        __RESET_WATCHDOG();    // Reset Watchdog
    }
}
